cmake_minimum_required(VERSION 3.14)

# 项目信息：使用 C++
project(tinycc VERSION 0.1.0 LANGUAGES CXX)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 设置输出目录（可执行文件放到 build/bin）
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 创建可执行文件
add_executable(tinycc 
    ${PROJECT_SOURCE_DIR}/src/main.cpp
    ${PROJECT_SOURCE_DIR}/src/lexer.cpp
)

# 添加 include 目录到头文件搜索路径
target_include_directories(tinycc PRIVATE ${PROJECT_SOURCE_DIR}/include)

# 编译选项：启用警告并视为错误（便于保持代码质量）
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    target_compile_options(tinycc PRIVATE
        -Wall
        -Wextra
        -Wpedantic
        -Werror
        -Wno-unused-parameter
        -Wno-unused-variable
        -g
        -O2
    )
elseif(MSVC)
    target_compile_options(tinycc PRIVATE
        /W4
        /WX
        /EHsc
    )
endif()

# Windows 特定定义（如需要）
if(WIN32)
    target_compile_definitions(tinycc PRIVATE UNICODE _UNICODE)
endif()

# 安装规则（可选）
install(TARGETS tinycc
    RUNTIME DESTINATION bin
)

# 启用测试（可选）
enable_testing()
add_test(NAME help_test
    COMMAND tinycc --help
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

